Repository navigation
test(tracker-core): [#2902] cover the statistics module - #2988
josecelano merged 40 commits into
Conversation
The merge of torrust#2903 has the same subject as the S0 commit, so the subject search found the merge commit first. Add --no-merges to the lookup in coverage-evidence.md and in the F8 and F18 verifications of the torrust#2903 review audit (review finding F20 of torrust#2903). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…orrust#2903 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ics repository plan Start S1: the shared file test plan guidance (T2) and the plan of the first ledger row, statistics/repository.rs, for the maintainer's approval. The plan proposes finding F6 (unused public gauge methods) and asks decision D1. The spec records S0 as merged and S1 in progress. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… and D1 Q2 after reading the code: the driver suites skip by design and db-compatibility.yaml runs them; S3 fixes the driver-test commands in the docs and a separate issue takes the visible skip and the published coverage. Q3 Docker-free S3, Q4 extract parse_valid_until in S2, Q5 quickcheck where natural, Q6 six slices, Q7 fix the temporary SQLite files in S1. F6 records the unused public gauge methods (D1: tested in S1). The statistics repository plan is approved. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ites and readers Ledger row 1 of S1. Add unit tests for the five write methods of statistics::repository::Repository (success, and the name collision the metric collection returns unchanged) and for a counter that is not in the collection reading as zero; one existing test asserts its three values as one tuple. The file goes from 86/140 to 277/277 lines (unit-only); all seven named mutations are killed. Plan and results in test-refactor-plans/statistics-repository-tests.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… in the S1 plans Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…atistics metrics `statistics/metrics.rs` only passes each call to its `MetricCollection`. The repository tests cover it 45 / 45 and kill all six hand-made mutants, so the maintainer approved no new test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s loader tests Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`load_persisted_metrics` had no unit test. Five tests with a mocked torrent-metrics store pin that a stored global total sets both the persistent and the persisted totals, that an empty store writes nothing, that a store failure is a database error, and that a refused write is a metrics error after the first total was already written (the load is not atomic). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…istics loader tests Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…stener tests Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`rustup update` moved stable from Rust 1.99.1 to 1.100.0, and `cargo-llvm-cov 0.6.16` then reported 0% for every file: it still read test binaries from `target/debug/deps/`, where Cargo 1.100.0 no longer writes them. With `cargo-llvm-cov 0.9.1` every figure of the issue is measured again at the same commits: the baseline at `5833cdae9` in five scopes and the unit-only runs after rows 1 and 3. The coverage evidence, the spec's baseline and ledger, the row records and the EPIC's torrust#2902 rows hold the new figures; the append-only logs keep the old ones. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…er entry points The tests covered only the private dispatch loops. Four tests run the two `*_unspawned` functions the application supervises and the two spawn wrappers over a real event bus: send one event, cancel, await the listener within a 5-second deadline, and check the counted or persisted download and, for the unspawned functions, the `Cancelled` completion. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…tener tests Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ndler tests Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…bal save failure of the statistics handlers Only `PeerAdded` stood for the events that must not count as a completed download, so counting `PeerRemoved` or `PeerUpdated` went unnoticed. Two table tests run all five such events through the in-memory and the persistent handler and replace the two `PeerAdded`-only tests. A third test pins that the persisted total does not move when the global downloads cannot be saved. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nt handler tests Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… repository tests Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…re incremented, not overwritten Every test increased a torrent's downloads once from nothing, so overwriting a stored total with 1 passed them all. Two tests on a temporary SQLite database increase the same torrent twice and the global total twice and expect 2. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…loads repository tests Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ests Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…atistics setting registers No test disabled usage statistics, so registering the in-session total regardless passed. One table test over the four combinations of usage and persisted statistics pins that the persistent total is always registered and the other two only with their setting, each at zero. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ule tests Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ment The S1 branch, rebased on `develop` `44ce734fe`, is measured in the four default scopes next to its base: unit-only lines 79.45% to 84.41%, aggregate 81.27% to 84.41%. The aggregate now equals unit-only, so the integration binary no longer reaches any `tracker-core` line the unit tests miss. The EPIC's torrust#2902 rows hold the latest values and row 14 is in progress. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… F20 follow-up Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
da2ce7
left a comment
There was a problem hiding this comment.
Reviewed at a05b5a02f62dc25a175923390b2be91dbc593fd2. Recomputed from the bytes at this head, against the merge base 44ce734fe; git merge-tree against develop 13c0ba42a writes a clean tree (the new develop merge touches only skills, its own issue and its own audit record).
Process: this round reads the eight commits since 09b91fe3e. The audit record is new. I ran the validator's logic offline over the captured comments and this branch's commit subjects: 7 rows, 2 log entries, no failure. Each of the seven threads has a reply on its own thread and an audit row, and is resolved. The two superseded rows use the prescribed reply form.
The change against its claim: each commit does what its message says. The three loop tables are now 14 named rstest cases. rstest = "0.28.0" is the version two sibling packages already pin, so the lock file gains no new package. The persistence cases now expect no torrent row at all. The failure test is named after the read it fails. Both EPIC lines sit in the Progress Log in date order. The listener and repository plans now name what the code does. F1 to F5 are fixed at this head. For F5, sample_info_hash parses a fixed literal, so the wider check is a strengthening, not a correction. F6 and F7 are superseded as recorded.
Consistency: the record's network-free verifications re-run as stated (no dated line under References, no cannot_be_saved, no join_within_deadline or Option<f64>). Links resolve. No added word is new to the tree.
Hygiene: the eight subjects follow the branch's Conventional form, and author equals committer. Each commit carries the same attribution footer as before; no rule in the tree forbids it. git diff --check is clean, the commit-id check prints nothing, and no closing keyword appears in the title, body or commits.
Findings: F21 Minor, the description still reports 180 unit tests and does not mention the new dev-dependency. F22 Nit, one Test Design row still promises the event's name in the message. None blocks.
Checked, no finding: the count of 191 unit test cases (180 less 3, plus 14); #[rstest] placed above #[tokio::test]; the generated case names against the replies; the history of the moved #2637 line; the record's frontmatter against the #2903 record.
Checks
On the loop's compute node at this head, against the merge base 44ce734fe (receipt server-gates-kranich-1326): the repository's pre-commit gate and lint roster exit 0 (197 s wall), and the audit validator passes on this PR's record (7 rows, 2 log entries, 0 failures). In the per-PR target directory, with every workspace crate recompiled at this head, cargo test --workspace passes 4467 tests with 0 failed and 5 ignored across 131 binaries (94 s wall), cargo clippy --workspace --all-targets --all-features -- -D warnings is clean, and cargo deny check exits 5 with the same license rejections and the same four advisories as recent runs on develop (identical error set). Checked against the bytes at posting: the PR description's Validation line still reports "180 unit" tests and does not mention the rstest dev-dependency, as F21 says. The head was confirmed with git ls-remote before posting. GitHub checks at this head at posting time: "Package Coverage (torrust-tracker-core): completed/success; Package Coverage (torrust-tracker): in_progress/pending; Discover Package Coverage: completed/success; Generate Coverage Report: completed/success; Database Compatibility MySQL (8.0): completed/success; Database Compatibility PostgreSQL (17): completed/success; Database Compatibility MySQL (8.4): completed/success; Database Compatibility PostgreSQL (16): completed/success; Database Compatibility PostgreSQL (14): completed/success; Database Compatibility PostgreSQL (15): completed/success; Persistence Benchmark SQLite3: completed/success; Persistence Benchmark MySQL: completed/success; Persistence Benchmark PostgreSQL: completed/success; Test (Docker) (release): in_progress/pending; Docker E2E: completed/skipped; Documented Clippy Allows: completed/success; Unit (stable): completed/success; Workspace Packaging: completed/success; Layer Boundary Bans: completed/success; Unit (nightly): in_progress/pending; Shipped Features: completed/success; Build on ubuntu-latest (nightly): completed/success; Build on macos-latest (stable): completed/success; Build on macos-latest (nightly): completed/success; Build on windows-latest (stable): completed/success; Build on windows-latest (nightly): completed/success; Build on ubuntu-latest (stable): completed/success; Docs Lint: completed/success". At posting, develop is bcca9764c.
|
ACK a05b5a0 — the eight commits since the round-1 head read against their messages, every round-1 finding re-checked as fixed or superseded, and the audit record passing the validator's logic offline at this head |
…test cases The handler plan still promised the event's name in each assertion message and called its two tests tables; each event is now an `rstest` case whose name carries the event. The module plan gets the same pointer. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rrust#2988 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Copilot review overview
2 open issues
3 resolved since last review
Review effort: Lite
…bal downloads failure test The mock of `load_torrent_downloads` allowed any number of calls, so a redundant read went unnoticed. Like the other expectations of the test, it now expects exactly one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…features The `add-rust-dependency` skill prefers `default-features = false`. The statistics tests use neither default feature of `rstest` (`async-timeout`, `crate-name`), so they are off, as in `axum-rest-api-server`. The version stays 0.28.0, the latest stable release. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rust#2988 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
ACK 71c0a0f |
da2ce7
left a comment
There was a problem hiding this comment.
Reviewed at 71c0a0f5ce6f9ea2e559327c55572c048de93d0b. Recomputed from the bytes at this head, against the merge base 44ce734fe; git merge-tree against develop 98fa27df2 writes a clean tree (develop's two new merges touch only other issues and their own audit records).
Process: this review covers the five commits since a05b5a02f. The record now holds 11 rows. Run offline over the capture, the validator's logic reports 11 rows, 4 log entries and no failure. All 11 root threads have a reply on their own thread and an audit row, and are resolved. That includes the two the automated reviewer opened at 10:03:41 UTC, after the previous head was pushed.
The change against its claim: 97e9699c5 adds .times(1) to expect_load_torrent_downloads (handler.rs:338-339). Production reads the torrent row once before saving it (persisted/downloads.rs:63), so the expectation holds. The test still fails for the reason its name states, the Err arm of increase_global_downloads; a redundant torrent read now fails it too. 31342ce9a turns off rstest's default features, as axum-rest-api-server does; the tests use no #[timeout] and no renamed crate. Cargo.lock rightly stays unchanged: it records no features, and the siblings that keep the defaults still pull the optional dependencies. 5ccaef5ae points the plan rows at their rstest cases, and F21 and F22 stay fixed.
Consistency: each new row's network-free verification prints what it says (handler.rs:338-339, Cargo.toml:50).
Hygiene: five Conventional subjects in the branch's form, and author equals committer. Each commit carries the same attribution footer as before; no rule in the tree forbids it. git diff --check is clean, the commit-id check prints nothing, and no closing keyword appears in the title, body or commits.
Findings: F25 Nit, the F23 row's severity departs from the record's own overview mapping. The record numbers the automated reviewer's two comments F23 and F24, so this review's finding is F25. It does not block.
Checked, no finding: F24 is recorded as FIXED for a declined version style plus a related change, which ten earlier rows in the tree also do; the 0.28.0 requirement matches three sibling packages; the round-3 log entry's reply times match the capture.
Checks
On the loop's compute node at this head, against the merge base 44ce734fe (receipt server-gates-kranich-1333): the repository's pre-commit gate and lint roster exit 0 (129 s wall), and the audit validator passes on this PR's record (11 rows, 4 log entries, 0 failures). In the per-PR target directory, with every workspace crate recompiled at this head, cargo test --workspace passes 4467 tests with 0 failed and 5 ignored across 131 binaries (87 s wall), and cargo clippy --workspace --all-targets --all-features -- -D warnings is clean. cargo deny check exits 5 with the same license rejections and advisories as recent runs on develop, plus one advisory published since then, RUSTSEC-2026-0592 against url 2.5.8; this PR does not change that entry of Cargo.lock, and develop at 98fa27df2 locks the same version. Checked against the bytes at posting: docs/pr-reviews/pr-2988-review/PR-REVIEW.md:67 records the F23 row as Nit (inferred), as F25 says, and packages/tracker-core/Cargo.toml:50 now reads rstest = { version = "0.28.0", default-features = false }. The head was confirmed with git ls-remote before posting. GitHub checks at this head at posting time: "Package Coverage (torrust-tracker-core): completed/success; Package Coverage (torrust-tracker): in_progress/pending; Docker E2E: completed/skipped; Documented Clippy Allows: completed/success; Workspace Packaging: completed/success; Unit (stable): in_progress/pending; Unit (nightly): in_progress/pending; Layer Boundary Bans: completed/success; Shipped Features: completed/success; Persistence Benchmark SQLite3: completed/success; Persistence Benchmark MySQL: completed/success; Persistence Benchmark PostgreSQL: completed/success; Database Compatibility MySQL (8.0): completed/success; Database Compatibility PostgreSQL (16): completed/success; Database Compatibility PostgreSQL (15): completed/success; Database Compatibility PostgreSQL (17): completed/success; Database Compatibility PostgreSQL (14): completed/success; Database Compatibility MySQL (8.4): completed/success; Discover Package Coverage: completed/success; Generate Coverage Report: in_progress/pending; Docs Lint: completed/success; Test (Docker) (release): in_progress/pending; Build on windows-latest (stable): completed/success; Build on macos-latest (nightly): completed/success; Build on ubuntu-latest (nightly): completed/success; Build on ubuntu-latest (stable): completed/success; Build on windows-latest (nightly): completed/success; Build on macos-latest (stable): completed/success". At posting, develop is 98fa27df2.
|
ACK 71c0a0f — the five commits since the round-2 head read against their messages, the one-read expectation and the rstest feature change checked against the code and lock file, and all eleven threads replied, recorded and resolved with the validator's logic passing at this head |
…t overview The overview of review `6011613619` marks F23 Medium, which the record maps to `Minor (inferred)` as it does for F5 and F6; the row said `Nit (inferred)`. The round 3 sentence now names both overview severities, as the round 1 sentence does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rrust#2988 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Copilot review overview
No open issues 🎉
2 resolved since last review
Review effort: Lite
|
ACK 5186511 |
da2ce7
left a comment
There was a problem hiding this comment.
Reviewed at 51865117852673d00812bbaba7329b2773706dd1. Recomputed from the bytes at this head, against the merge base 44ce734fe; git merge-tree against develop 98fa27df2 writes a clean tree (develop has not moved since the last trial merge).
Process: this round reads the two commits since 71c0a0f5c. Both change only the pull request's own audit record; the path listing of merge-pull-request prints that one file. Run offline over the capture, the validator's logic reports 12 rows, 5 log entries and no failure. All 12 root threads have a reply on their own thread and an audit row, and are resolved. The automated reviewer's review of 71c0a0f5c (10:30:14 UTC, after this head's push) reports no open issue and adds no thread.
The change against its claim: 2da9871a5 does what it says. The F23 row reads Minor (inferred), following the overview's Medium as F5 and F6 do, and the round-3 sentence names both overview severities. 518651178 records round 4: the F25 row and its details, a round-4 sentence, and a 10:26 log entry whose reply time matches the capture. F25 is fixed. Every earlier finding (F1 to F7, F21 to F24) is unchanged, because no file of theirs moved.
Consistency: the F25 row's verification prints the F23 row with Minor (inferred), now at line 70. The F25 row's severity, Nit, matches its source bracket. The description is unchanged since the last review.
Hygiene: two Conventional subjects in the branch's form, and author equals committer. Each commit carries the same attribution footer as before; no rule in the tree forbids it. git diff --check is clean, the commit-id check prints nothing, and no closing keyword appears in the title, body or commits.
Findings: none.
Checked, no finding: the round-4 sentence names the reviewed head by its subject and gives the review's time as the capture has it; the log entries stay in time order; the new no-issue review needs no row.
Checks
On the loop's compute node at this head, against the merge base 44ce734fe (receipt server-gates-kranich-1339): the repository's pre-commit gate and lint roster exit 0 (48 s wall), and the audit validator passes on this PR's record (12 rows, 5 log entries, 0 failures). This head differs from 71c0a0f5c only in docs/pr-reviews/pr-2988-review/PR-REVIEW.md, so the package measurements made there (receipt server-gates-kranich-1333) hold: in the per-PR target directory, with every workspace crate recompiled, cargo test --workspace passes 4467 tests with 0 failed and 5 ignored across 131 binaries, cargo clippy --workspace --all-targets --all-features -- -D warnings is clean, and cargo deny check matches recent runs on develop plus the newly published RUSTSEC-2026-0592 against url 2.5.8, which develop locks too. Checked against the bytes at posting: PR-REVIEW.md:70 now records the F23 row as Minor (inferred), the fix for F25. The head was confirmed with git ls-remote before posting. GitHub checks at this head at posting time: "Package Coverage (torrust-tracker-core): in_progress/pending; Package Coverage (torrust-tracker): in_progress/pending; Test (Docker) (release): in_progress/pending; Docs Lint: in_progress/pending; Database Compatibility MySQL (8.0): completed/success; Database Compatibility PostgreSQL (14): completed/success; Database Compatibility MySQL (8.4): completed/success; Database Compatibility PostgreSQL (17): completed/success; Database Compatibility PostgreSQL (15): completed/success; Database Compatibility PostgreSQL (16): completed/success; Docker E2E: completed/skipped; Shipped Features: completed/success; Layer Boundary Bans: completed/success; Documented Clippy Allows: completed/success; Unit (stable): in_progress/pending; Unit (nightly): in_progress/pending; Workspace Packaging: completed/success; Discover Package Coverage: completed/success; Persistence Benchmark MySQL: completed/success; Persistence Benchmark PostgreSQL: completed/success; Generate Coverage Report: in_progress/pending; Persistence Benchmark SQLite3: completed/success; Build on ubuntu-latest (nightly): completed/success; Build on windows-latest (stable): in_progress/pending; Build on ubuntu-latest (stable): completed/success; Build on macos-latest (stable): completed/success; Build on macos-latest (nightly): completed/success; Build on windows-latest (nightly): in_progress/pending". At posting, develop is 98fa27df2.
|
ACK 5186511 — the two audit-only commits since the round-3 head read against their messages, F25 confirmed fixed, and all twelve threads replied, recorded and resolved with the validator's logic passing at this head |
|
ACK 5186511 |


Related to #2902
Slice S1 of #2902: focused unit tests for
packages/tracker-core/src/statistics/, the one area oftracker-corethat only the integration binary reached. Test code, documentation and one dev-dependency (rstest0.28.0, already in the lock file): no production line changes.Each file went through the spec's per-file workflow: a plan approved by the maintainer, the tests, hand-made named mutations, and a completed-file review. The plans and their results are in
docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/.statistics/repository.rsstatistics/metrics.rsstatistics/persisted/mod.rsload_persisted_metricswith a mocked store, including that the load is not atomicstatistics/event/listener.rsstatistics/event/handler.rsrstesttables over every event that is not a completed download (replacing twoPeerAdded-only tests) and a test where the global downloads cannot be increasedstatistics/persisted/downloads.rsstatistics/mod.rs,statistics/event/mod.rsrstesttable of which totals each statistics setting registers;event/mod.rsdeclares modules onlyCoverage of
tracker-core(stable Rust 1.100.0,cargo-llvm-cov 0.9.1, against thedevelopbase44ce734fe): unit-only lines 79.45% to 84.41% (180 unit tests at the measured commit, 157 before), aggregate 81.27% to 84.41%. The aggregate now equals the unit-only figure line for line, so the integration binary no longer reaches any line the unit tests miss. Everystatistics/file runs all its lines; the regions left aretracinglog-level checks, one unreachable error arm and test code. Details:coverage-evidence.md, section "Slice Measurements".Also in this PR:
torrust-tracker-corepackage #2902 was measured again with Rust 1.100.0 andcargo-llvm-cov 0.9.1, at the maintainer's request: afterstablemoved from Rust 1.99.1,cargo-llvm-cov 0.6.16reported 0% for every file because it read test binaries from Cargo's oldtarget/debug/deps/layout. The baseline is now 79.32% unit-only lines (80.31% with the old toolchain). The append-only logs keep the old figures.tracker-corehold the latest values; row 14 is in progress.docs/pr-reviews/pr-2988-review/PR-REVIEW.md): the three loop tables became 14 namedrstestcases, which addsrstestas a dev-dependency of the package; the persistence cases expect no torrent row for any info-hash; a test name and plan text were corrected; the S1 log entry moved into the EPIC Progress Log, with a stray Overhaul Packages Testing: Add tests foraxum-rest-api-serverpackage #2637 entry.Validation at the head after review round 1:
cargo test -p torrust-tracker-core --all-features(191 unit test cases, 15 integration and 18 other tests),cargo clippy -p torrust-tracker-core --all-targets --all-features,cargo +nightly fmt --all -- --check, the pre-commit gate on every commit, and the repository's pre-push checks on push.🤖 Generated with Claude Code